package thingtest.game;

public class Vector {

	protected double x;
	protected double y;
	
	public Vector(){
		x=0;
		y=0;
	}

	public Vector(double x, double y) {
		this.x= x;
		this.y= y;
	}

	public boolean sameDirectionAs(Vector anotherVector) {

		return ((anotherVector.normalizedDirectionX() == this.normalizedDirectionX()) && (anotherVector.normalizedDirectionY() == this.normalizedDirectionY()));

	}

	private double normalizedDirectionY() {
	
		return this.y/this.norm();
	}

	public double norm() {
		
		double result = this.x*this.x + this.y*this.y;
		
		return Math.sqrt(result);
	}

	private double normalizedDirectionX() {

		return this.x/this.norm();
	}
	
	public Vector normalized(){
		Vector result = new Vector(this.normalizedDirectionX(),this.normalizedDirectionY());
		return result;
		
	}
	
	public void add(Vector vector){
		this.x = this.x + vector.x;
		this.y = this.y + vector.y;
	}
	
	protected Vector createCopy() {
		return new Vector(this.x,this.y);
	}
	
	public Vector goInThisDirection(Vector speed) {
		Vector newVector = this.createCopy();
		newVector.add(speed);
		return newVector;
	}

	public boolean isTheSameAs(Vector anotherVector) {
		return ((this.x == anotherVector.x) && (this.y == anotherVector.y));
	}

	public Vector minus(Vector anotherVector) {
		Vector returnedVector = new Vector(this.x - anotherVector.x , this.y - anotherVector.y);
		return returnedVector;
		
	}

	public Vector makeACopy() {
		return new Vector(this.x,this.y);
	}


}
